<template>
  <div class="body">
    <!-- <el-row v-if="!hasData" class="no-data">
      <div align="right">
        <el-button type="primary" @click="add">新增</el-button>
      </div>
      <h3 align="center">无数据</h3>
    </el-row> -->
    <el-row>
      <el-row class="title" style="margin: 0px 25px 0px 15px" type="flex">
        <el-col :sm="24" align="right">
          <!-- <el-button type="primary" @click="getStrokeOutsData">重置</el-button> -->
          <el-button type="primary" @click="save">保存</el-button>
        </el-col>
      </el-row>
      <el-form :model="outcomeForm" label-position="left" label-width="110px" class="box-outCome-stroke">
        <el-row type="flex" class="inner_indent">
          <div>
            <el-form-item label="患者出院方式：" label-width="120px" required>
              <el-select v-model="outcomeForm.outComeCode" @change="getStrokeOutsData">
                <el-option v-for="(outComeItem, outComeIndex) in outComeList" :key="'outCome' + outComeIndex"
                  :label="outComeItem.outComeName" :value="outComeItem.outComeCode" />
              </el-select>
            </el-form-item>
          </div>
          <div v-if="outcomeForm.outComeCode && outcomeForm.outComeCode !== '4'" class="date">
            <el-form-item label="住院时间" required>
              <el-date-picker v-model="outcomeForm.inpatientTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" />
            </el-form-item>
          </div>
          <div v-if="outcomeForm.outComeCode === '2'">
            <el-form-item label="医院名称：">
              <el-input v-model="outcomeForm.handHospitalName" />
            </el-form-item>
          </div>
          <div v-if="outcomeForm.outComeCode === '2' || outcomeForm.outComeCode === '1'">
            <el-form-item label="病案首页出院主要诊断名称：" label-width="210px" required>
              <el-input v-model="outcomeForm.out_main_diagnosis_name" />
            </el-form-item>
          </div>
          <div v-if="outcomeForm.outComeCode === '2' || outcomeForm.outComeCode === '1'">
            <el-form-item label="病案首页出院主要诊断编码：" label-width="210px" required>
              <el-input v-model="outcomeForm.out_main_diagnosis_code" />
            </el-form-item>
          </div>
        </el-row>

        <el-row v-if="outcomeForm.outComeCode === '2'">
          <el-row type="flex" class="inner_indent">
            <div v-if="outcomeForm.outComeCode === '2'">
              <el-form-item label="离院方式：" required>
                <el-select v-model="outcomeForm.leavingHospitalType">
                  <el-option v-for="(
                      leavingHospitalTypeItem, leavingHospitalTypeIndex
                    ) in leavingHospitalTypeList.filter(
                        (el) => el.type === '1'
                      )" :key="'leavingHospitalType' + leavingHospitalTypeIndex"
                    :label="leavingHospitalTypeItem.leavingHospitalTypeName"
                    :value="leavingHospitalTypeItem.leavingHospitalTypeCode" />
                </el-select>
              </el-form-item>
            </div>
            <div class="date">
              <el-form-item label="出院时间" required>
                <el-date-picker v-model="outcomeForm.handTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="住院号：" required>
                <el-input v-model="outcomeForm.inpatientId" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="住院天数：" required>
                <el-input v-model="outcomeForm.hod" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="总费用：" required>
                <el-input v-model="outcomeForm.totalCost" />
              </el-form-item>
            </div>
          </el-row>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode === '1'">
          <el-row type="flex" class="inner_indent">
            <div>
              <el-form-item label="出院诊断：">
                <el-select v-model="outcomeForm.diagnosisCode">
                  <el-option v-for="(diagnosisItem, diagnosisIndex) in diagnosisList"
                    :key="'diagnosis' + diagnosisIndex" :label="diagnosisItem.diagnosisName"
                    :value="diagnosisItem.diagnosisCode" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="住院号：" required>
                <el-input v-model="outcomeForm.inpatientId" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="住院天数：" required>
                <el-input v-model="outcomeForm.hod" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="总费用：" required>
                <el-input v-model="outcomeForm.totalCost" />
              </el-form-item>
            </div>
          </el-row>
          <el-row v-if="outcomeForm.outComeCode && outcomeForm.outComeCode === '1'" class="inner_indent">
            <el-form-item label="出院带药：" label-width="110px" required>
              <check-string-group v-model="outcomeForm.outDrug" :list="dischargeMedicineList"
                field="dischargeMedicine" />
            </el-form-item>
          </el-row>
          <el-row v-if="outcomeForm.diagnosisCode == '3'" class="inner_indent" style="margin: 5px 0px 10px 0">
            出院GCS评分：
          </el-row>
          <el-row v-if="outcomeForm.diagnosisCode == '3'" class="inner_indent">
            <gcs v-model="outcomeForm.leaveGcsMark" @totle="outcomeForm.leaveGcsTotal = $event" />
          </el-row>

          <el-row class="inner_indent">
            <div class="radio-mrs">
              <el-form-item label="出院mRS评分：" label-width="140px"
                :required="Number(this.outcomeForm.hod) >= 5 && Number(this.outcomeForm.hod) <= 9" required>
                <el-radio-group v-model="outcomeForm.leaveMrsValue">
                  <el-radio v-for="(
                      leaveMrsValueItem, leaveMrsValueIndex
                    ) in leaveMrsValueList" :key="'leaveMrsValue' + leaveMrsValueIndex"
                    :label="leaveMrsValueItem.leaveMrsValueCode">
                    {{ leaveMrsValueItem.leaveMrsValueName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <el-form-item label="出院NIHSS评分：" label-width="180px"
              :required="Number(this.outcomeForm.hod) >= 5 && Number(this.outcomeForm.hod) <= 9" required />
            <div class="inner_indent radio-mrs">
              <el-form-item label="意识水平：" label-width="106px">
                <el-radio-group v-model="outcomeForm.nihssList[0]" @change="nihssChange">
                  <el-radio v-for="(levelItem, levelIndex) in levelList" :key="'level' + levelIndex"
                    :label="levelItem.levelCode">
                    {{ levelItem.levelName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="意识水平提问（月份、年龄）：" label-width="250px">
                <el-radio-group v-model="outcomeForm.nihssList[1]" @change="nihssChange">
                  <el-radio v-for="(askItem, askIndex) in askList" :key="'ask' + askIndex" :label="askItem.askCode">
                    {{ askItem.askName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="意识水平提问（睁闭眼、握拳松开）：" label-width="250px">
                <el-radio-group v-model="outcomeForm.nihssList[2]" @change="nihssChange">
                  <el-radio v-for="(askItem, askIndex) in askList" :key="'ask' + askIndex" :label="askItem.askCode">
                    {{ askItem.askName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="眼睛-凝视：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[3]" @change="nihssChange">
                  <el-radio v-for="(gazeItem, gazeIndex) in gazeList" :key="'gaze' + gazeIndex"
                    :label="gazeItem.gazeCode">
                    {{ gazeItem.gazeName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="眼睛-视野：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[4]" @change="nihssChange">
                  <el-radio v-for="(viewItem, viewIndex) in viewList" :key="'view' + viewIndex"
                    :label="viewItem.viewCode">
                    {{ viewItem.viewName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="面部-面瘫：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[5]" @change="nihssChange">
                  <el-radio v-for="(paralysisItem, paralysisIndex) in paralysisList" :key="'paralysis' + paralysisIndex"
                    :label="paralysisItem.paralysisCode">
                    {{ paralysisItem.paralysisName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent radio-mrs">
              <el-form-item label="上肢运动（左上肢）：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[6]" @change="nihssChange">
                  <el-radio v-for="(limbItem, limbIndex) in limbList" :key="'limb' + limbIndex"
                    :label="limbItem.limbCode">
                    {{ limbItem.limbName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent radio-mrs">
              <el-form-item label="上肢运动（右上肢）：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[7]" @change="nihssChange">
                  <el-radio v-for="(limbItem, limbIndex) in limbList" :key="'limb' + limbIndex"
                    :label="limbItem.limbCode">
                    {{ limbItem.limbName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>

          <el-row class="inner_indent">
            <div class="inner_indent radio-mrs">
              <el-form-item label="下肢运动（左上肢）：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[8]" @change="nihssChange">
                  <el-radio v-for="(legItem, legIndex) in legList" :key="'leg' + legIndex" :label="legItem.legCode">
                    {{ legItem.legName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent radio-mrs">
              <el-form-item label="下肢运动（右上肢）：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[9]" @change="nihssChange">
                  <el-radio v-for="(legItem, legIndex) in legList" :key="'leg' + legIndex" :label="legItem.legCode">
                    {{ legItem.legName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>

          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="肢体共济失调：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[10]" @change="nihssChange">
                  <el-radio v-for="(limbAtaxiaItem, limbAtaxiaIndex) in limbAtaxiaList"
                    :key="'limbAtaxia' + limbAtaxiaIndex" :label="limbAtaxiaItem.limbAtaxiaCode">
                    {{ limbAtaxiaItem.limbAtaxiaName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="感觉：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[11]" @change="nihssChange">
                  <el-radio v-for="(feelItem, feelIndex) in feelList" :key="'feel' + feelIndex"
                    :label="feelItem.feelCode">
                    {{ feelItem.feelName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="语言（命名、阅读测试）：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[12]" @change="nihssChange">
                  <el-radio v-for="(langItem, langIndex) in langList" :key="'lang' + langIndex"
                    :label="langItem.langCode">
                    {{ langItem.langName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="构音障碍（读或重复表上的单词）：" label-width="240px">
                <el-radio-group v-model="outcomeForm.nihssList[13]" @change="nihssChange">
                  <el-radio v-for="(obstacleItem, obstacleIndex) in obstacleList" :key="'obstacle' + obstacleIndex"
                    :label="obstacleItem.obstacleCode">
                    {{ obstacleItem.obstacleName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <div class="inner_indent">
              <el-form-item label="消退或不注意忽视：" label-width="180px">
                <el-radio-group v-model="outcomeForm.nihssList[14]" @change="nihssChange">
                  <el-radio v-for="(subsideItem, subsideIndex) in subsideList" :key="'subside' + subsideIndex"
                    :label="subsideItem.subsideCode">
                    {{ subsideItem.subsideName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent" type="flex">
            <div class="inner_small">
              <el-form-item label="NIHSS评分结果：" label-width="130px">
                <el-input v-model="outcomeForm.leaveNihssTotal" disabled />
              </el-form-item>
            </div>
            <div class="vertical-center">分</div>
            <div>
              <el-form-item label="" label-width="0px">
                <el-input v-model="outcomeForm.nihssDiscribe" disabled />
              </el-form-item>
            </div>
          </el-row>
          <el-row class="inner_indent">
            <el-form-item label="康复治疗场所：" label-width="120px">
              <el-checkbox-group v-model="outcomeForm.treatmentPlaceCheck">
                <el-checkbox v-for="(
                    treatmentPlaceItem, treatmentPlaceIndex
                  ) in treatmentPlaceList" :key="'treatmentPlace' + treatmentPlaceIndex"
                  :label="treatmentPlaceItem.treatmentPlaceCode">
                  {{ treatmentPlaceItem.treatmentPlaceName }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
          <el-row type="flex" class="inner_indent">
            <el-form-item label="康复治疗方式：" label-width="120px">
              <el-checkbox-group v-model="outcomeForm.treatmentTypeCheck">
                <el-checkbox v-for="(
                    treatmentTypeItem, treatmentTypeIndex
                  ) in treatmentTypeList" :key="'treatmentType' + treatmentTypeIndex"
                  :label="treatmentTypeItem.treatmentTypeCode">
                  {{ treatmentTypeItem.treatmentTypeName }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
          <el-row class="inner_indent">
            <el-form-item label="宣教方式：" label-width="120px">
              <el-checkbox-group v-model="outcomeForm.propagandaTypeCheck">
                <el-checkbox v-for="(
                    propagandaTypeItem, propagandaTypeIndex
                  ) in propagandaTypeList" :key="'propagandaType' + propagandaTypeIndex"
                  :label="propagandaTypeItem.propagandaTypeCode">
                  {{ propagandaTypeItem.propagandaTypeName }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
          <el-row type="flex" class="inner_indent">
            <div class="date">
              <el-form-item label="出院时间" label-width="120px">
                <el-date-picker v-model="outcomeForm.leaveTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="离院方式：" label-width="120px">
                <el-select v-model="outcomeForm.leavingHospitalType">
                  <el-option v-for="(
                      leavingHospitalTypeItem, leavingHospitalTypeIndex
                    ) in leavingHospitalTypeList.filter(
                        (el) => el.type === '2'
                      )" :key="'leavingHospitalType' + leavingHospitalTypeIndex"
                    :label="leavingHospitalTypeItem.leavingHospitalTypeName"
                    :value="leavingHospitalTypeItem.leavingHospitalTypeCode" />
                </el-select>
              </el-form-item>
            </div>
          </el-row>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode === '4'">
          <el-row type="flex" class="inner_indent">
            <div class="date">
              <el-form-item label="死亡时间：" label-width="120px">
                <el-date-picker v-model="outcomeForm.deathTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="死亡原因：" label-width="120px">
                <el-radio-group v-model="outcomeForm.deathCause">
                  <el-radio v-for="(deathCauseItem, deathCauseIndex) in deathCauseList"
                    :key="'deathCause' + deathCauseIndex" :label="deathCauseItem.deathCauseCode">
                    {{ deathCauseItem.deathCauseName }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-row>
          <el-row v-if="outcomeForm.deathCause == '99'" class="inner_indent">
            <el-form-item label="死亡原因：" label-width="120px">
              <el-input v-model="outcomeForm.deathCauseOther" type="textarea" :rows="2" />
            </el-form-item>
          </el-row>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode && outcomeForm.outComeCode === '2'" class="inner_indent">
          <el-form-item label="出院带药：" label-width="110px" required>
            <check-string-group v-model="outcomeForm.outDrug" :list="dischargeMedicineList" field="dischargeMedicine" />
          </el-form-item>
        </el-row>
      </el-form>
    </el-row>
  </div>
</template>

<script>
import {
  getStrokeOutsData,
  saveStrokeOutsData,
  selectStrokeNIHSS
} from '@/api/green-channel/outcome'
import CheckStringGroup from '@/components/Score/CheckStringGroup'
import Gcs from '@/components/Score/Gcs'

import { getPatientStroke } from '@/api/green-channel/info'

export default {
  components: {
    CheckStringGroup,
    Gcs
  },
  props: {
    checkrowdata: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      outcomeForm: {
        treatmentPlaceCheck: [],
        treatmentTypeCheck: [],
        propagandaTypeCheck: [],
        nihssList: new Array(15)
      },
      outDeath: ['deathTime', 'deathCause', 'deathCauseOther'],
      outReturn: [
        'inpatientTime',
        'handHospitalName',
        'leavingHospitalType',
        'handTime',
        'outDrug'
      ],
      outDept: [
        'inpatientTime',
        'diagnosisCode',
        'inpatientId',
        'leaveGcsMark',
        'leaveGcsTotal',
        'leaveMrsValue',
        'nihssList',
        'leaveNihssTotal',
        'nihssDiscribe',
        'treatmentPlaceCheck',
        'treatmentTypeCheck',
        'propagandaTypeCheck',
        'leaveTime',
        'leavingHospitalType',
        'outDrug',
        'deathCause'
      ],
      // 离院方式-转院
      leavingHospitalTypeList: [
        {
          leavingHospitalTypeName: '医嘱转院',
          leavingHospitalTypeCode: '2',
          type: '1'
        },
        {
          leavingHospitalTypeName: '医嘱转社区卫生服务机构/乡镇卫生院',
          leavingHospitalTypeCode: '3',
          type: '1'
        },

        {
          leavingHospitalTypeName: '医嘱离院',
          leavingHospitalTypeCode: '1',
          type: '2'
        },
        {
          leavingHospitalTypeName: '非医嘱离院',
          leavingHospitalTypeCode: '4',
          type: '2'
        }
      ],
      // 出院诊断
      diagnosisList: [
        { diagnosisName: '脑梗死', diagnosisCode: '1' },
        { diagnosisName: '脑出血', diagnosisCode: '2' },
        { diagnosisName: '自发性蛛网膜下腔出血', diagnosisCode: '3' },
        { diagnosisName: 'TIA', diagnosisCode: '4' },
        { diagnosisName: '未破裂颅内动脉瘤', diagnosisCode: '5' },
        { diagnosisName: '颈动脉狭窄或闭塞', diagnosisCode: '6' },
        { diagnosisName: '动静脉畸形AVM', diagnosisCode: '7' },
        { diagnosisName: '烟雾病', diagnosisCode: '8' }
      ],
      // 出院mRS评分
      leaveMrsValueList: [
        { leaveMrsValueName: '完全无症状', leaveMrsValueCode: '0' },
        {
          leaveMrsValueName:
            '尽管有症状，但无明显功能障碍，能完成所有日常职责和活动',
          leaveMrsValueCode: '1'
        },
        {
          leaveMrsValueName:
            '轻度残疾，不能完成病前所有活动，但不需要帮助，能照顾自己的事务',
          leaveMrsValueCode: '2'
        },
        {
          leaveMrsValueName: '中度残疾，要求一些帮助，但行走不需要帮助',
          leaveMrsValueCode: '3'
        },
        {
          leaveMrsValueName:
            '重度残疾，不能独立行走，无他人帮助不能满足自身需求',
          leaveMrsValueCode: '4'
        },
        {
          leaveMrsValueName: '严重残疾，卧床、失禁、要求持续护理和关注',
          leaveMrsValueCode: '9'
        }
      ],
      // 康复治疗场所
      treatmentPlaceList: [
        { treatmentPlaceName: '床旁', treatmentPlaceCode: '1' },
        { treatmentPlaceName: '康复科', treatmentPlaceCode: '2' }
      ],
      // 康复治疗方式
      treatmentTypeList: [
        {
          treatmentTypeName: '传统康复（针灸 、推拿）',
          treatmentTypeCode: '01'
        },
        { treatmentTypeName: '运动疗法（PT）', treatmentTypeCode: '02' },
        { treatmentTypeName: '作业疗法（OT）', treatmentTypeCode: '03' },
        { treatmentTypeName: '言语训练（ST）', treatmentTypeCode: '04' },
        {
          treatmentTypeName: '其他（认知训练、吞咽治疗、心理治疗、理疗）',
          treatmentTypeCode: '99'
        }
      ],
      // 宣教方式
      propagandaTypeList: [
        { propagandaTypeName: '集体病区教育', propagandaTypeCode: '01' },
        { propagandaTypeName: '一对一教育', propagandaTypeCode: '02' },
        { propagandaTypeName: '其他', propagandaTypeCode: '99' }
      ],
      // 离院方式-转院
      outModeList: [],
      // 死亡类型
      deathCauseList: [
        { deathCauseName: '呼吸循环衰竭', deathCauseCode: '01' },
        { deathCauseName: '脑血管病', deathCauseCode: '02' },
        { deathCauseName: '肺部感染', deathCauseCode: '03' },
        { deathCauseName: '上消化道出血', deathCauseCode: '04' },
        { deathCauseName: '急性肾功能衰竭', deathCauseCode: '05' },
        { deathCauseName: '损伤和中毒', deathCauseCode: '06' },
        { deathCauseName: '不详', deathCauseCode: '98' },
        { deathCauseName: '其他', deathCauseCode: '99' }
      ],
      // NIHSS评分
      // 意识水平
      levelList: [
        { levelName: '清醒，反应灵敏', levelCode: '0' },
        {
          levelName: '嗜睡，轻微刺激能唤醒，可回答问题，执行指令',
          levelCode: '1'
        },
        {
          levelName:
            '昏睡或反应迟钝，需反复刺激、强烈或疼痛刺激才有非刻板的反应',
          levelCode: '2'
        },
        {
          levelName:
            '昏迷，仅有反射性活动或自发性反应或完全无反应、软瘫、无反射',
          levelCode: '3'
        }
      ],
      // 意识水平提问（月份、年龄）||意识水平提问（睁闭眼、握拳松开）
      askList: [
        { askName: '两项均正确', askCode: '0' },
        { askName: '一项正确', askCode: '1' },
        { askName: '两项均不正确', askCode: '2' }
      ],
      // 眼睛-凝视
      gazeList: [
        { gazeName: '正常', gazeCode: '0' },
        {
          gazeName:
            '部分凝视麻痹（单眼或双眼凝视异常，但无强迫凝视或完全凝视麻痹）',
          gazeCode: '1'
        },
        {
          gazeName:
            '部分凝视麻痹（单眼或双眼凝视异常，但无强迫凝视或完全凝视麻痹）',
          gazeCode: '2'
        }
      ],
      // 眼睛-视野
      viewList: [
        { viewName: '无视野缺损', viewCode: '1' },
        { viewName: '部分偏盲', viewCode: '2' },
        { viewName: '完全偏盲', viewCode: '3' },
        { viewName: '双侧偏盲（包括皮质盲）', viewCode: '4' }
      ],
      // 面部-面瘫
      paralysisList: [
        { paralysisName: '正常', paralysisCode: '0' },
        {
          paralysisName: '轻微（微笑时鼻唇沟变平、不对称）',
          paralysisCode: '1'
        },
        {
          paralysisName: '部分（下面部完全或几乎完全瘫痪）',
          paralysisCode: '2'
        },
        {
          paralysisName: '完全（单或双侧瘫痪，上下面部缺乏运动）',
          paralysisCode: '3'
        }
      ],
      // 上肢运动
      limbList: [
        { limbName: '无下落，置肢体于90o （或45o ）坚持10秒', limbCode: '0' },
        {
          limbName: '能抬起但不能坚持10秒，下落时不撞击床或其他支持物',
          limbCode: '1'
        },
        { limbName: '试图抵抗重力，但不能维持坐位90o或仰位45o', limbCode: '2' },
        { limbName: '不能抵抗重力，肢体快速下落', limbCode: '3' },
        { limbName: '无运动', limbCode: '4' },
        { limbName: '截肢或关节融合(解释：5a左上肢; 5b右上肢)', limbCode: '9' }
      ],
      // 下肢运动
      legList: [
        { legName: '无下落，于要求位置坚持5秒', legCode: '0' },
        { legName: '5秒末下落，不撞击床', legCode: '1' },
        { legName: '5秒内下落到床上，可部分抵抗重力', legCode: '2' },
        { legName: '立即下落到床上，不能抵抗重力', legCode: '3' },
        { legName: '无运动', legCode: '4' },
        { legName: '截肢或关节融合(解释：5a左上肢; 5b右上肢)', legCode: '9' }
      ],
      // 肢体共济失调
      limbAtaxiaList: [
        { limbAtaxiaName: '无共济失调', limbAtaxiaCode: '0' },
        { limbAtaxiaName: '一个肢体有', limbAtaxiaCode: '1' },
        { limbAtaxiaName: '两个肢体有', limbAtaxiaCode: '2' },
        {
          limbAtaxiaName: '截肢或关节融合(解释：左上肢1=有,2=无)',
          limbAtaxiaCode: '9'
        }
      ],
      // 感觉
      feelList: [
        { feelName: '正常', feelCode: '0' },
        {
          feelName:
            '轻-中度感觉障碍，（患者感觉针刺不尖锐或迟钝，或针刺感缺失但有触觉）',
          feelCode: '1'
        },
        { feelName: '重度-完全感觉缺失（面、上肢、下肢无触觉）', feelCode: '2' }
      ],
      // 语言（命名、阅读测试）
      langList: [
        { langName: '正常', langCode: '0' },
        {
          langName: '轻-中度失语：流利程度和理解能力部分下降，但表达无明显受限',
          langCode: '1'
        },
        {
          langName:
            '严重失语，交流是通过患者破碎的语言表达，听者须推理、询问、猜测，交流困难',
          langCode: '2'
        },
        {
          langName: '不能说话或者完全失语，无言语或听力理解能力',
          langCode: '3'
        }
      ],
      // 构音障碍（读或重复表上的单词）
      obstacleList: [
        { obstacleName: '正常', obstacleCode: '0' },
        {
          obstacleName: '轻-中度，至少有些发音不清，虽有困难但能被理解',
          obstacleCode: '1'
        },
        {
          obstacleName:
            '言语不清，不能被理解，但无失语或  与失语不成比例，或失音',
          obstacleCode: '2'
        },
        { obstacleName: '气管插管或其他物理障碍', obstacleCode: '9' }
      ],
      // 消退或不注意忽视
      subsideList: [
        { subsideName: '正常', subsideCode: '0' },
        {
          subsideName:
            '视、触、听、空间觉或个人的忽视；或对一种感觉的双侧同时刺激忽视',
          subsideCode: '1'
        },
        {
          subsideName:
            '严重的偏侧忽视或一种以上的偏侧忽视；不认识自己的手；只能对一侧空间定位',
          subsideCode: '2'
        }
      ],
      // 患者出院方式
      outComeList: [
        {
          outComeName: '转送其它医院',
          outComeCode: '2'
        },
        {
          outComeName: '出院',
          outComeCode: '1'
        },
        {
          outComeName: '死亡',
          outComeCode: '4'
        }
      ],
      // 出院带药
      dischargeMedicineList: [
        { dischargeMedicineName: '降压药', dischargeMedicineCode: '01' },
        { dischargeMedicineName: '降糖药', dischargeMedicineCode: '02' },
        { dischargeMedicineName: '调脂药', dischargeMedicineCode: '03' },
        { dischargeMedicineName: '抗凝药', dischargeMedicineCode: '04' },
        { dischargeMedicineName: '抗血小板药', dischargeMedicineCode: '05' },
        { dischargeMedicineName: '中药治疗', dischargeMedicineCode: '06' },
        { dischargeMedicineName: '其他', dischargeMedicineCode: '07' },
        { dischargeMedicineName: '无', dischargeMedicineCode: '98' }
      ],
      inpatientId: '' // 住院id
      // hasData: false
    }
  },
  created() {
    this.getStrokeOutsData()
    this.getPatientInfo()
  },
  methods: {
    // 查询卒中转归数据信息
    getPatientInfo() {
      getPatientStroke(
        this.checkrowdata.patientId,
        this.checkrowdata.dispatchId
      ).then((res) => {
        // console.log(res)
        if (res.data) {
          this.inpatientId = res.data.inpatientId
        }
      })
    },
    selectStrokeNIHSS() {
      selectStrokeNIHSS(this.checkrowdata.dispatchId).then((res) => {
        // console.log(res)
        if (res.data) {
          console.log('res.data.list', res.data.list)
          res.data.list.forEach(el => {
            if (el.type === '出院NIHSS评分') {
              this.outcomeForm.leaveNihssTotal = el.score
              this.outcomeForm.nihssDiscribe = el.result

              console.log(this.outcomeForm.leaveNihssTotal, this.outcomeForm.nihssDiscribe)
            }
          })
        }
      })
    },
    getStrokeOutsData(val = '') {
      // console.log('出院')
      // console.log(this.outcomeForm.outComeCode)
      if (this.outcomeForm.outComeCode == '1') {
        for (let i = 0; i < this.outcomeForm.nihssList.length; i++) {
          this.outcomeForm.nihssList[i] = '0'
        }
      }
      this.selectStrokeNIHSS()
      getStrokeOutsData({
        dispatchId: this.checkrowdata.dispatchId
      }).then((res) => {
        if (res.data != null) {
          // this.hasData = true
          this.outcomeForm = res.data
          if (this.outcomeForm.leaveNihssMark) {
            this.$set(
              this.outcomeForm,
              'nihssList',
              this.outcomeForm.leaveNihssMark.split('|')
            )
          } else {
            this.$set(this.outcomeForm, 'nihssList', new Array(15))
            for (let i = 0; i < this.outcomeForm.nihssList.length; i++) {
              this.outcomeForm.nihssList[i] = '0'
            }
          }
          this.nihssGrade()
          // 多选框字段数据处理
          this.interceptSemicolon('treatmentPlace')
          this.interceptSemicolon('treatmentType')
          this.interceptSemicolon('propagandaType')
          // this.interceptSemicolon('deathCause')
          this.interceptSemicolon('dischargeMedicine')
          // 患者出院方式对应字段初始化
          if (val && res.data.outComeCode !== val) {
            this.outcomeForm.outComeCode = val
            if (val === '1') {
              this.clearField('outDept')
              this.outcomeForm.nihssList = new Array(13)
              for (let i = 0; i < this.outcomeForm.nihssList.length; i++) {
                this.outcomeForm.nihssList[i] = '0'
              }
              console.log(this.outcomeForm)
            }
            if (val === '2') {
              this.clearField('outReturn')
            }
            if (val === '4') {
              this.clearField('outDeath')
            }
          }
        } else {
          // 判断是否有数据
          if (!this.outcomeForm.outComeCode) {
            // this.hasData = false
          }
        }
      })
    },
    // 清空对应患者出院方式的字段信息
    clearField(formField) {
      this[formField].forEach((field) => {
        if (field.indexOf('Check') < 0) {
          this.$set(this.outcomeForm, field, '')
        } else {
          this.$set(this.outcomeForm, field, [])
        }
      })
    },
    // 多选框字段字符串转数组
    interceptSemicolon(feild) {
      if (
        typeof this.outcomeForm[feild] !== 'undefined' &&
        this.outcomeForm[feild] != null &&
        this.outcomeForm[feild] !== ''
      ) {
        this.$set(
          this.outcomeForm,
          feild + 'Check',
          this.outcomeForm[feild].match(/;(\S*);/)[1].split(';')
        )
      } else {
        this.$set(this.outcomeForm, feild + 'Check', [])
      }
    },
    // NIHSS评分计算
    nihssChange() {
      let sum = 0
      for (let i = 0; i < this.outcomeForm.nihssList.length; i++) {
        if (this.outcomeForm.nihssList[i]) {
          sum += parseInt(this.outcomeForm.nihssList[i])
        }
      }
      this.outcomeForm.leaveNihssTotal = sum
      this.nihssGrade()
    },
    // NIHSS评分等级判断
    nihssGrade() {
      const score = parseInt(this.outcomeForm.leaveNihssTotal)
      if (score >= 0 && score <= 1) {
        this.outcomeForm.nihssDiscribe = '正常或近乎正常'
      }
      if (score >= 1 && score <= 4) {
        this.outcomeForm.nihssDiscribe = '轻度卒中/小卒中'
      }
      if (score >= 5 && score <= 15) {
        this.outcomeForm.nihssDiscribe = '中度卒中'
      }
      if (score >= 15 && score <= 20) {
        this.outcomeForm.nihssDiscribe = '中-重度卒中'
      }
      if (score >= 21) {
        this.outcomeForm.nihssDiscribe = '重度卒中'
      }
    },
    // 保存前数据处理
    requireCheck() {
      if (this.outcomeForm.outComeCode == 4) {
        return true
      }
      if (this.outcomeForm.inpatientTime == '' || !this.outcomeForm.inpatientTime || this.outcomeForm.inpatientTime.length == 0) {
        this.$message.warning('住院时间必须选择!')
        return
      }
      if (this.outcomeForm.hod == '' || !this.outcomeForm.hod || this.outcomeForm.hod.length == 0) {
        this.$message.warning('住院天数必须填写!')
        return
      }
      if (this.outcomeForm.out_main_diagnosis_name == '' || !this.outcomeForm.out_main_diagnosis_name || this.outcomeForm.out_main_diagnosis_name.length == 0) {
        this.$message.warning('病案首页出院主要诊断名称必须填写!')
        return
      }
      if (this.outcomeForm.out_main_diagnosis_code == '' || !this.outcomeForm.out_main_diagnosis_code || this.outcomeForm.out_main_diagnosis_code.length == 0) {
        this.$message.warning('病案首页出院主要诊断编码必须填写!')
        return
      }
      if (this.outcomeForm.totalCost == '' || !this.outcomeForm.totalCost || this.outcomeForm.totalCost.length == 0) {
        this.$message.warning('总费用必须填写!')
        return
      }
      if (this.outcomeForm.inpatientId == '' || !this.outcomeForm.inpatientId || this.outcomeForm.inpatientId.length == 0) {
        this.$message.warning('住院号必须填写!')
        console.log('住院号必须填写!', this.outcomeForm)
        return
      }

      if (this.outcomeForm.outComeCode == 1) {
        if (this.outcomeForm.outDrug == '' || !this.outcomeForm.outDrug || this.outcomeForm.outDrug.length <= 2) {
          this.$message.warning('出院带药必须选择!')
          return
        }
        // console.log(this.outcomeForm)
        // if (this.outcomeForm.leaveMrsValue == '' || !this.outcomeForm.leaveMrsValue) {
        //   this.$message.warning('出院mRS评分必须选择!')
        //   return
        // }
        // for (const nihssList_index in this.outcomeForm.nihssList) {
        //     if (this.outcomeForm.nihssList[nihssList_index] == '' || !this.outcomeForm.nihssList[nihssList_index] || this.outcomeForm.nihssList[nihssList_index].length == 0) {
        //       this.$message.warning('出院NIHSS评分必须选择完整!')
        //       return
        //     }
        //   }
        //       7±2天（或出院）时mRS评分
        // 7±2天（或出院）时NIHSS评分

        if (Number(this.outcomeForm.hod) >= 5 && Number(this.outcomeForm.hod) <= 9) {
          if (this.outcomeForm.leaveMrsValue == '' || !this.outcomeForm.leaveMrsValue || this.outcomeForm.leaveMrsValue.length == 0) {
            this.$message.warning('出院mRS评分必须选择!')
            return
          }
          for (const nihssList_index in this.outcomeForm.nihssList) {
            console.log("nihssList_index", nihssList_index)
            if (this.outcomeForm.nihssList[nihssList_index] == '' || !this.outcomeForm.nihssList[nihssList_index] || this.outcomeForm.nihssList[nihssList_index].length == 0) {
              this.$message.warning('出院NIHSS评分必须选择完整!')
              return
            }
          }
        }


      }
      return true

    },
    save() {
      if (!this.requireCheck()) {
        return
      }
      this.getName('leavingHospitalType')
      this.getName('diagnosis', 'Code')
      this.getName('outCome', 'Code')
      this.getName('deathCause')
      this.getNameList('treatmentPlace')
      this.getNameList('treatmentType')
      this.getNameList('propagandaType')
      if (this.outcomeForm.deathCause !== '99') {
        this.outcomeForm.deathCauseOther = ''
      }
      this.outcomeForm.nihssList.forEach((item) => {
        if (!item) {
          item = ''
        }
      })
      this.outcomeForm.leaveNihssMark = this.outcomeForm.nihssList.join('|')
      this.outcomeForm.dispatchId = this.checkrowdata.dispatchId
      this.saveStrokeOutsData(this.outcomeForm)
    },
    // 调用保存接口
    saveStrokeOutsData(data) {
      saveStrokeOutsData(data).then((res) => {
        this.$message.success('保存成功')
        this.getStrokeOutsData()
      })
    },
    // 查询多选框的key值对应的名称
    getNameList(field, str = '') {
      // eslint-disable-next-line prefer-const
      let name = []
      console.log(this.outcomeForm['treatmentPlaceCheck'])
      this.outcomeForm[field + str + 'Check'].forEach((el) => {
        console.log(1)
        this[field + 'List'].forEach((item) => {
          console.log(2)
          if (item[field + 'Code'] === el) {
            name.push(item[field + 'Name'])
          }
        })
      })
      this.outcomeForm[field + 'Name'] = name.join(';')
      this.outcomeForm[field] =
        ';' + this.outcomeForm[field + str + 'Check'].join(';') + ';'
    },
    // 查询单选的key值对应的名称
    getName(field, str = '') {
      let name = ''
      this[field + 'List'].forEach((item) => {
        if (item[field + 'Code'] === this.outcomeForm[field + str]) {
          name = item[field + 'Name']
        }
      })
      this.outcomeForm[field + 'Name'] = name
    }
    // add() {
    //   this.hasData = true
    // }
  }
}
</script>

<style lang="scss" scoped>
.body {
  padding: 0px 20px 60px 20px;
  font-size: 14px;
  color: #606266;

  .no-data {
    padding: 20px 40px;
    color: #000;
    font-size: 1.17em;
  }

  .title {
    font-size: 20px;
    color: #1890ff;
  }

  .box-outCome-stroke {
    padding-left: 35px;
  }

  .radio {
    &-mrs {
      margin-top: 6px;

      .el-radio {
        min-width: 400px;
      }
    }
  }

  .subTitle {
    font-size: 16px;
    margin-top: 5px;
    margin-bottom: 5px;
  }
}
</style>
<style lang="scss">
.box-outCome-stroke {
  .el-form-item {
    margin-top: 4px;
    margin-bottom: 4px;

    &__label {
      font-weight: normal;
    }

    &--medium {
      .el-form-item {
        &__label {
          line-height: 25px;
        }

        &__content {
          line-height: 25px;
        }
      }
    }
  }

  .el-radio {
    line-height: 25px !important;
  }

  .el-input--medium {
    .el-input__inner {
      height: 25px;
      line-height: 25px;
      padding-left: 10px;
    }

    .el-input__icon {
      line-height: 25px;
    }
  }

  .el-select {
    margin-right: 60px;
  }

  .el-date-editor.el-input {
    width: 195px;
    margin-right: 60px;
  }

  .date {
    .el-input--medium {
      .el-input__inner {
        padding-left: 30px;
        padding-right: 20px;
      }
    }
  }

  .inner_indent {
    padding-left: 15px;
  }

  .inner_small {
    margin-right: 5px;
    width: 200px;
  }

  .vertical-center {
    display: flex;
    align-items: center;
    padding-left: 0px;
    padding-right: 10px;
  }
}
</style>
